#include "Task.hpp"
#include "BlockQueue.hpp"
#include <pthread.h>

//生产者消费者模型
void* producer(void* args)
{
    BlockQueue<task_t> * bq = static_cast<BlockQueue<task_t>*>(args);
    while(true)
    {
        bq->Equeue(Download);//这里先形成tast_t的临时对象，临时对象是个右值传递给T&就是权限放大
    }
}

void* consumer(void* args)
{
    BlockQueue<task_t> *bq = static_cast<BlockQueue<task_t>*>(args);
    while(true)
    {
        task_t task = bq->Pop();
        task();
    }
}


int main()
{
    BlockQueue<task_t> * bq = new BlockQueue<task_t>();

    pthread_t p[3],c[2];

    pthread_create(c,nullptr,consumer,bq);
    pthread_create(c+1,nullptr,consumer,bq);
    pthread_create(p,nullptr,producer,bq);
    pthread_create(p+1,nullptr,producer,bq);
    pthread_create(p+2,nullptr,producer,bq);

    pthread_join(c[0],nullptr);
    pthread_join(c[1],nullptr);
    pthread_join(p[0],nullptr);
    pthread_join(p[1],nullptr);
    pthread_join(p[2],nullptr);

    return 0;
}